/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.coupon.controller;

import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.FxConfMsgTemplate;
import com.ykht.proj.coupon.service.FxConfMsgTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 消息模板表
 *
 * @author proj code generator
 * @date 2021-02-05 15:50:11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/fxconfmsgtemplate")
@Api(value = "fxconfmsgtemplate", tags = "消息模板表管理")
public class FxConfMsgTemplateController {

	private final FxConfMsgTemplateService fxConfMsgTemplateService;

	/**
	 * 查询全部
	 */
	@ApiOperation(value = "查询全部", notes = "查询全部")
	@GetMapping("/findAll")
//	@PreAuthorize("@pms.hasPermission('coupon_fxconfmsgtemplate_view')" )
	public R getFxConfMsgTemplate() {
		List<FxConfMsgTemplate> list = fxConfMsgTemplateService.list();
		return R.ok(list);
	}

	/**
	 * 新增或修改平台基本配置
	 *
	 * @param list 平台基本配置
	 * @return R
	 */
	@ApiOperation(value = "新增或修改消息模板表", notes = "新增或修改消息模板表")
	@SysLog("新增或修改消息模板表")
	@PostMapping
//	@PreAuthorize("@pms.hasPermission('coupon_fxconfmsgtemplate_add')" )
	public R save(@RequestBody List<FxConfMsgTemplate> list) {

		for (FxConfMsgTemplate fxConfMsgTemplate : list) {
			if (null == fxConfMsgTemplate.getId() || "".equals(fxConfMsgTemplate.getId())) {
				fxConfMsgTemplate.setCreateUser(SecurityUtils.getUserId());
				fxConfMsgTemplate.setCreateTime(LocalDateTime.now());
			}
			fxConfMsgTemplate.setUpdateUser(SecurityUtils.getUserId());
			fxConfMsgTemplate.setUpdateTime(LocalDateTime.now());
		}
		return R.ok(fxConfMsgTemplateService.saveOrUpdateBatch(list));
	}


}
